﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Collector
{
    public class GlobalConfigure
    {
        private TestItemConfig _TestItemCfg = new TestItemConfig();
        public TestItemConfig TestItemCfg
        {
            get { return _TestItemCfg; }
            set { _TestItemCfg = value; }
        }

        private TestModeConfig _TestModeCfg = new TestModeConfig();
        public TestModeConfig TestModeCfg
        {
            get { return _TestModeCfg; }
            set { _TestModeCfg = value; }
        }

        private EnumCustomerType _CurrentCustomer = EnumCustomerType.NA;
        public EnumCustomerType CurrentCustomer
        {
            get { return _CurrentCustomer; }
            set { _CurrentCustomer = value; }
        }

        private EnumTestEndAcyionType _TestEndAction = EnumTestEndAcyionType.NA;
        public EnumTestEndAcyionType TestEndAction
        {
            get { return _TestEndAction; }
            set { _TestEndAction = value; }
        }

        //public MESConfig MESCfg { get; set; }
        public bool SaveConfig(string filename)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(filename))
                    throw new Exception("file name is empty!");

                XmlHelper.SaveConfig<GlobalConfigure>(this, filename);
                return true;
            }
            catch
            {
                return false;
            }

        }
        public GlobalConfigure ReadConfig(string filename, out string errmsg)
        {
            errmsg = "";
            try
            {
                GlobalConfigure obj = new GlobalConfigure();
                if (!XmlHelper.GetConfig<GlobalConfigure>(filename, ref obj) || obj == null)
                    return null;
                return obj;
            }
            catch (Exception ex)
            {
                errmsg = ex.Message;
                return null;
            }
        }

        //public BaseConfig GetSubConfig(string typeName)
        //{
        //    if (typeName == "AudioTest")
        //        return AudioTestCfg;
        //    return null;
        //}
        private static readonly GlobalConfigure instance = new GlobalConfigure();
        public static GlobalConfigure GetGlobalConfigure()
        {
            return instance;
        }

        public GlobalConfigure()
        {
            //this.MESCfg = new MESConfig();
            this.TestItemCfg = new TestItemConfig();
            this.TestModeCfg = new TestModeConfig();
        }
    }

    /*public class MESConfig
    {
        private bool _EnableOnLine = false;

        public bool EnableOnLine
        {
            get { return _EnableOnLine; }
            set { _EnableOnLine = value; }
        }
        private string _CurrentStationId = "";

        public string CurrentStationId
        {
            get { return _CurrentStationId; }
            set { _CurrentStationId = value; }
        }
        private string _CcurrentStationName = "";

        public string CcurrentStationName
        {
            get { return _CcurrentStationName; }
            set { _CcurrentStationName = value; }
        }
    }*/

    public class TestItemConfig
    {
        private bool _WritePCBSN = false;
        public bool WritePCBSN
        {
            get { return _WritePCBSN; }
            set { _WritePCBSN = value; }
        }

        private bool _LedTest = false;
        public bool LedTest
        {
            get { return _LedTest; }
            set { _LedTest = value; }
        }

        private bool _PulsePressure = false;
        public bool PulsePressure
        {
            get { return _PulsePressure; }
            set { _PulsePressure = value; }
        }

        private bool _AirPressure = false;
        public bool AirPressure
        {
            get { return _AirPressure; }
            set { _AirPressure = value; }
        }
    }
    public class TestModeConfig
    {
        private bool _FactoryTest = false;
        public bool FactoryTest
        {
            get { return _FactoryTest; }
            set { _FactoryTest = value; }
        }

        private bool _UserTest = false;
        public bool UserTest
        {
            get { return _UserTest; }
            set { _UserTest = value; }
        }
    }
    
    public enum EnumCustomerType
    {
        NA,
        MI,
        ASUS,
        LenovoQualcomm,
        ASUSQualcomm,
        WeiBuQualcomm,
        XiaoMiQualcomm,
        HUAWEI
    }

    public enum EnumTestEndAcyionType
    {
        NA,
        SHUTDOWN,
        RESTART,
        START_PE,
        QCOM_BTWIFI,
        QCOM_REVERT,
        EXIT_APP
    }

}
